<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>伯恩斯焦虑状况电子自查表</title>
    <style>
        :root {
            --primary-color: #2c3e50;
            --secondary-color: #3498db;
            --active-color: #e3f2fd;
        }
    
        body {
            font-family: system-ui, arial, 'Segoe UI', sans-serif;
            line-height: 1.4;
            margin: 0;
            background-color: #f8f9fa;
        }

        #title {
            text-align: center;
        }
        #helpmsg {
            text-align: center;
        }
    
        .container {
            max-width: 800px;
            margin: 0 auto;
            background: white;
            padding: 1rem;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        }
    
        .question-card {
            display: none;
            padding: 1rem;
            border: 2px solid var(--primary-color);
            border-radius: 8px;
            margin: 0.5rem 0;
            background: #f8fafc;
        }
    
        .options-grid {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 0.5rem;
            margin: 1rem 0;
        }
    
        .option-btn {
            padding: 0.8rem;
            border: 2px solid #ddd;
            border-radius: 6px;
            cursor: pointer;
            transition: all 0.2s;
            background: white;
            text-align: center;
            font-size: 16px;
            line-height: 1.3;
        }
    
        input:checked + .option-btn {
            border-color: var(--secondary-color);
            background: var(--active-color);
            font-weight: bold;
        }
    
        .nav-buttons {
            display: flex;
            justify-content: space-between;
            gap: 0.5rem;
            margin-top: 1rem;
        }
    
        button {
            background-color: var(--secondary-color);
            color: white;
            padding: 0.8rem 1rem;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            transition: opacity 0.2s;
            font-size: 14px;
        }
        button:disabled {
            background: #95a5a6 !important;
            cursor: not-allowed;
            opacity: 0.7;
        }

        #startBtn {
            font-size: 2em;
            width: 100%;
        }
    
        #result {
            padding: 1rem;
            margin: 1rem 0;
            border-radius: 8px;
            background: var(--active-color);
            font-size: 1rem;
            text-align: center;
            display: none;
        }
    
        @media (max-width: 480px) {
            .container {
                padding: 0.5rem;
                margin: 0;
            }
    
            .question-card {
                margin: 0.25rem 0;
                padding: 0.75rem;
            }
    
            .options-grid {
                grid-template-columns: 1fr;
                gap: 0.3rem;
            }
    
            .option-btn {
                padding: 0.6rem;
                font-size: 13px;
            }
    
            button {
                padding: 0.6rem 0.8rem;
                min-width: auto;
            }
    
            #currentQuestion h3 {
                font-size: 16px;
                margin: 0.5rem 0;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <h2 id="title">伯恩斯焦虑状况自查表</h2>
        <p id="helpmsg">请根据 <b>过去一周</b> 中这些症状或问题困扰你的程度，选择最符合实际情况的一项。</p>
        <button id="startBtn">开始测试</button>
        <div class="question-card">
            <div id="currentQuestion"></div>
            <div class="options-grid" id="optionsContainer"></div>
            <div class="nav-buttons">
                <button onclick="showPreviousQuestion()" id="prevBtn" disabled>上一题</button>
                <button onclick="startOrContinueTest()" id="nextBtn">开始测试</button>
            </div>
        </div>
        <p style="text-align:center; color:#666; font-size:0.9em; margin:2rem 0 0.5rem; line-height:1.6">
            本测评工具基于《伯恩斯新情绪疗法II》理论开发，<b>仅供自我筛查参考，不构成专业医学诊断。</b><br>
            <b>开发者不</b>对因使用本工具产生的任何后果<b>承担责任</b>，包括但不限于误诊、治疗延误等。<br>
            <b>如果您决定使用本工具，表明您同意以上条款。</b>
        </p>
        <div id="result"></div>
    </div>

<script>
const questions = [
    "焦虑、紧张、担忧或恐惧",
    "感觉身边的一切事物怪异、不真实或暧昧不清",
    "感觉身体的一部分或全部与自己脱离",
    "突然感到恐慌",
    "感觉大难临头或有不祥的预感",
    "感觉紧张、压力大、'绷得紧紧的'或走投无路",
    "难以集中精力",
    "思维翻腾或跳跃",
    "有恐怖阴森的想法或幻想",
    "感觉处于崩溃的边缘",
    "害怕失控或发疯",
    "害怕昏倒或晕厥",
    "害怕生病或心脏病发作或死亡",
    "担心在别人面前出丑或露拙",
    "害怕孤单，害怕被人隔离或抛弃",
    "害怕批评或反对",
    "害怕有不好的事要发生",
    "心律不齐、心跳加速或剧烈跳动（心悸）",
    "胸口痛、有压迫感或胸闷",
    "脚趾或手指有刺痛感和麻木感",
    "胃痛或肠胃不适",
    "便秘或腹泻",
    "焦躁不安",
    "肌肉紧绷、紧张",
    "出冷汗",
    "喉咙哽咽",
    "颤抖或摇晃",
    "大腿发软或绵软无力",
    "眩晕、头晕或感觉失去平衡",
    "感觉窒息或透不过气来或呼吸困难",
    "头痛、脖子痛或后背痛",
    "浑身潮热或打冷颤",
    "感觉疲倦、虚弱或很容易筋疲力尽"
];

let testSession = {
    progress: {},
    questionOrder: [],
    currentIndex: 0
};

function initializeTest() {
    testSession = {
        progress: {},
        questionOrder: [...questions.keys()].sort(() => Math.random() - 0.5),
        currentIndex: 0
    };
    updateQuestion();
    document.getElementById('prevBtn').disabled = true;
}

function updateQuestion() {
    const realIndex = testSession.questionOrder[testSession.currentIndex];
    document.getElementById('currentQuestion').innerHTML = `
        <h3><span style="color:#666; font-size:0.9em">（${testSession.currentIndex + 1}/${questions.length}）</span> 
        ${questions[realIndex]}</h3>
    `;
    
    document.getElementById('optionsContainer').innerHTML = [0, 1, 2, 3].map(score => `
        <label>
            <input type="radio" name="answer" value="${score}" 
                   onchange="saveAnswer()" style="display:none">
            <div class="option-btn">${['完全没有', '轻度', '中度', '重度'][score]}</div>
        </label>
    `).join('');

    if(testSession.progress[realIndex] !== undefined) {
        document.querySelector(`input[value="${testSession.progress[realIndex]}"]`).checked = true;
    }

    document.getElementById('prevBtn').disabled = testSession.currentIndex === 0;
    document.getElementById('nextBtn').textContent = 
        testSession.currentIndex === questions.length - 1 ? '提交评估' : '下一题';

    // 新增答案状态检测
    const hasAnswer = testSession.progress[realIndex] !== undefined;
    document.getElementById('nextBtn').disabled = !hasAnswer;
}

function saveAnswer() {
    const selected = document.querySelector('input[name="answer"]:checked');
    if(selected) {
        const realIndex = testSession.questionOrder[testSession.currentIndex];
        testSession.progress[realIndex] = selected.value;
        document.getElementById('nextBtn').disabled = false; // 立即激活按钮
    }
}

function showNextQuestion() {
    if(testSession.currentIndex === questions.length - 1) return calculateScore();
    
    testSession.currentIndex++;
    updateQuestion();
}

function showPreviousQuestion() {
    testSession.currentIndex--;
    updateQuestion();
}

function calculateScore() {
    const total = Object.values(testSession.progress).reduce((sum, val) => sum + parseInt(val), 0);
    let result = `<div style="text-align:left; margin:1rem 0">`;
    
    // 更新为焦虑评分标准
    const thresholds = [
        {min: 0,  max: 4,  label: "极少或完全没有焦虑", color: "#27ae60"},
        {min: 5,  max: 10, label: "近似焦虑",          color: "#2ecc71"},
        {min: 11, max: 20, label: "轻度焦虑",          color: "#f1c40f"},
        {min: 21, max: 30, label: "中度焦虑",          color: "#e67e22"},
        {min: 31, max: 50, label: "重度焦虑",          color: "#e74c3c"},
        {min: 51, max: 99, label: "极度焦虑或恐慌",     color: "#c0392b"}
    ];

    const level = thresholds.find(l => total >= l.min && total <= l.max) || thresholds[5];
    
    // 更新结果展示
    result += `
        <h3 style="margin:0.5rem 0; text-align:center">焦虑程度：<span style="color:${level.color}">${level.label}</span></h3>
        <p style="text-align:center; margin:0.5rem 0 1.5rem; color:#666">
            测评得分：<strong style="font-size:1.2em">${total}</strong> 分
            <br><small>（评分范围：${level.min}-${level.max}分）</small>
        </p>
    `;

    // 更新提示信息
    result += `
        <div style="background:#fee; padding:0.8rem; border-radius:6px; margin-top:1rem; text-align:left">
            <p style="margin:0.2rem 0; font-size:13px; color:#c0392b">
                <strong>重要提示：</strong><br>
                ${total >= 11 ? 
                    "⚠️ 如果您的得分持续在11分以上，建议寻求专业帮助" : 
                    "✅ 您的得分在正常波动范围内"
                }
                <br>* 焦虑症状可能影响生活质量，请及时关注心理健康
            </p>
        </div>
    `;

    document.getElementById('result').innerHTML = result;
    document.getElementById('result').style.display = 'block';
    window.scrollTo({ top: document.body.scrollHeight, behavior: 'smooth' });
}

function startOrContinueTest() {
    testSession.questionOrder.length === 0 ? initializeTest() : showNextQuestion();
}

document.getElementById('startBtn').addEventListener('click', function() {
    this.style.display = 'none'; // 隐藏开始按钮
    document.querySelector('.question-card').style.display = 'block'; // 显示问题卡片
    initializeTest(); // 直接初始化测试
});
</script>
</body>
</html>